Ext.onReady(function() {
    getTools= function(target){
        return [{
            xtype: 'tool',
            type: 'gear',
            handler: function(e, target, panelHeader, tool){
                var portlet = panelHeader.ownerCt;
                portlet.query('gridpanel')[0].getStore().load();
                
//                portlet.setLoading('Working...');
//                Ext.defer(function() {
//                    portlet.setLoading(false);
//                }, 2000);
            }
        }];
    }	
	
	var PortalPanel=Ext.create('Ext.app.PortalPanel',{
		bodyPadding: 10,
        items: [{
        	id:'portal-col-1'
        },{
        	id:'portal-col-2'
        }]
	});
	
	var AppPortal=Ext.create('Ext.container.Viewport',{
        layout:'fit',
		renderTo: 'index-panel',
		items:[PortalPanel]
	});	
	
	Ext.Ajax.request({
		url : '/index_display/',
		method : 'post',
		success : function(response) {
			var json = Ext.JSON.decode(response.responseText);
			if(json.success){
				for(var i=0;i<json.data.length;i++){
					if(i%2 == 0){
						Ext.getCmp('portal-col-1').add({
							title:json.data[i].text,
							tools: getTools(),
							frame:false,
							margin:'5 5 5 5',
							items: Ext.create(json.data[i].portlet)
						});					
					}else{
						Ext.getCmp('portal-col-2').add({
							title:json.data[i].text,
							tools: getTools(),
							frame:false,
							margin:'5 5 5 5',
							items: Ext.create(json.data[i].portlet)
						});						
					}
				}
			}else{
				Ext.Msg.alert('系统提示', json.message);
			}
		}
	});	
	
});